/*
 * 介绍:系统缓存仓库
 */
export default defineStore("SysStore", {
  //*全局仓库
  state: initState,
  //*全局函数
  actions: {
    setReqHeader(set: Partial<ReqHeader>) {
      this.$patch((state) => {
        state.reqHeader = { ...state.reqHeader, ...set };
      });
    },
    setSetting(set: Partial<Setting>) {
      this.$patch((state) => {
        state.setting = { ...state.setting, ...set };
      });
    },
  },
  //*计算属性
  getters: {},
  //*仓库数据缓存
  persist: [
    {
      key: "SysStore",
      storage: localStorage, //指定储存位置
    },
  ],
});
/**state类型定义 */
interface SysStore {
  setting: Setting;
  reqHeader: AnyObject | undefined;
}

export interface ReqHeader {
  language: string;
}

/**设置 */
export interface Setting {
  language: string;
  theme: "dark" | "light";
}

/**初始化pinia */
function initState(): SysStore {
  return {
    setting: {
      language: import.meta.env.VITE_DEFAULT_LANG,
      theme: "dark",
    },
    reqHeader: undefined,
  };
}
